package com.ruoyi.control.service.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; //添加
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.control.mapper.AuxiliaryFanMapper;
import com.ruoyi.control.domain.AuxiliaryFan;
import com.ruoyi.control.service.IAuxiliaryFanService;

/**
 * 局扇Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-12-03
 */
@Service
public class AuxiliaryFanServiceImpl extends ServiceImpl<AuxiliaryFanMapper, AuxiliaryFan> implements IAuxiliaryFanService //修改
{
    @Autowired
    private AuxiliaryFanMapper auxiliaryFanMapper;

    /**
     * 查询局扇
     * 
     * @param tagName 局扇主键
     * @return 局扇
     */
    @Override
    public AuxiliaryFan selectAuxiliaryFanByTagName(String tagName)
    {
        return auxiliaryFanMapper.selectAuxiliaryFanByTagName(tagName);
    }

    /**
     * 查询局扇列表
     * 
     * @param auxiliaryFan 局扇
     * @return 局扇
     */
    @Override
    public List<AuxiliaryFan> selectAuxiliaryFanList(AuxiliaryFan auxiliaryFan)
    {
        return auxiliaryFanMapper.selectAuxiliaryFanList(auxiliaryFan);
    }

    /**
     * 新增局扇
     * 
     * @param auxiliaryFan 局扇
     * @return 结果
     */
    @Override
    public int insertAuxiliaryFan(AuxiliaryFan auxiliaryFan)
    {
        return auxiliaryFanMapper.insertAuxiliaryFan(auxiliaryFan);
    }

    /**
     * 修改局扇
     * 
     * @param auxiliaryFan 局扇
     * @return 结果
     */
    @Override
    public int updateAuxiliaryFan(AuxiliaryFan auxiliaryFan)
    {
        auxiliaryFan.setUpdateTime(DateUtils.getNowDate());
        return auxiliaryFanMapper.updateAuxiliaryFan(auxiliaryFan);
    }

    /**
     * 批量删除局扇
     * 
     * @param tagNames 需要删除的局扇主键
     * @return 结果
     */
    @Override
    public int deleteAuxiliaryFanByTagNames(String[] tagNames)
    {
        return auxiliaryFanMapper.deleteAuxiliaryFanByTagNames(tagNames);
    }

    /**
     * 删除局扇信息
     * 
     * @param tagName 局扇主键
     * @return 结果
     */
    @Override
    public int deleteAuxiliaryFanByTagName(String tagName)
    {
        return auxiliaryFanMapper.deleteAuxiliaryFanByTagName(tagName);

    }

    @Override
    public List<AuxiliaryFan> getList() {
        List<AuxiliaryFan> auxiliaryFanList = new ArrayList<>();
        List<String> fanData = Arrays.asList("jushan_1/fj1.Uab","jushan_1/fj1.Ia","jushan_1/Analog.T1","jushan_1/Analog.T1_g","jushan_1/Analog.T2",
                "jushan_1/fj2.Uab","jushan_1/fj2.Ia","jushan_1/Analog.T3","jushan_1/Analog.T4","jushan_1/Analog.T2_g","jushan_1/Analog.CH4_1","jushan_1/Analog.CH4_2",
                "jushan_2/fj1.Uab","jushan_2/fj1.Ia","jushan_2/Analog.T1","jushan_2/Analog.T1_g","jushan_2/Analog.T2",
                "jushan_2/fj2.Uab","jushan_2/fj2.Ia","jushan_2/Analog.T3","jushan_2/Analog.T4","jushan_2/Analog.T2_g","jushan_2/Analog.CH4_1","jushan_2/Analog.CH4_2",
                "jushan_4/fj1.Uab","jushan_4/fj1.Ia","jushan_4/Analog.T1","jushan_4/Analog.T1_g","jushan_4/Analog.T2",
                "jushan_4/fj2.Uab","jushan_4/fj2.Ia","jushan_4/Analog.T3","jushan_4/Analog.T4","jushan_4/Analog.T2_g","jushan_4/Analog.CH4_1","jushan_4/Analog.CH4_2");
        for (String fanDatum : fanData) {
            AuxiliaryFan auxiliaryFan = auxiliaryFanMapper.selectAuxiliaryFanByTagName(fanDatum);
//            if (auxiliaryFan != null && auxiliaryFan.getValue() != null){
                if (auxiliaryFan != null ){
                    String tagName = auxiliaryFan.getTagName();
                    String replace1 = tagName.replace("/", "_");
                    String replace = replace1.replace(".", "_");
                    auxiliaryFan.setTagName(replace);
                    if (auxiliaryFan.getValue() != null){
                        Double aDouble = Double.valueOf(auxiliaryFan.getValue());
                        auxiliaryFan.setValue(String.format("%.2f",aDouble));
                    }
                }
            auxiliaryFanList.add(auxiliaryFan);
        }
        return auxiliaryFanList;
    }

    @Override
    public List<AuxiliaryFan> getModelList() {
        List<AuxiliaryFan> auxiliaryFanList = new ArrayList<>();
        List<String> fanData = Arrays.asList("jushan_1/Analog.jk","jushan_1/Analog.yk",
              "jushan_2/Analog.jk","jushan_2/Analog.yk",
             "jushan_4/Analog.jk","jushan_4/Analog.yk");
        for (String fanDatum : fanData) {
            AuxiliaryFan auxiliaryFan = auxiliaryFanMapper.selectAuxiliaryFanByTagName(fanDatum);
            if (auxiliaryFan != null ){
                String tagName = auxiliaryFan.getTagName();
                String replace1 = tagName.replace("/", "_");
                String replace = replace1.replace(".", "_");
                auxiliaryFan.setTagName(replace);
            }
            auxiliaryFanList.add(auxiliaryFan);
        }
        return auxiliaryFanList;
    }
}
